﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace SpaceInvaders
{
    public class Tiro : Icon
    {
        //new public static Texture2D texture { get; set; }
        //public Vector2 position { get; private set; }
        //public Rectangle collisionRect { get; private set; }
        //ContentManager content;

        public Tiro(Vector2 playerPosition, Vector2 playerSize, Color color, Texture2D texture)
            :base(texture, color, new Vector2(playerPosition.X + (playerSize.X / 2), playerPosition.Y - playerSize.Y))
        {
            //content.RootDirectory = "Content";
            //content.Load<Texture2D>(@"Imagens\tiro");
            //collisionRect = new Rectangle((int)playerPosition.X, (int)playerPosition.Y, (int)texture.Width, (int)texture.Height); 
        }

        public void Move(float deltaY)
        {
            position = new Vector2(position.X, position.Y + deltaY);
            //collisionRect = new Rectangle((int)position.X, (int)position.Y, (int)texture.Width, (int)texture.Height);
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, Color.White);
        }

        public static Tiro[] AddToList(Tiro[] tiros, Tiro tiro)
        {            
            if (tiros != null)
            {
                Tiro[] buffer = tiros;
                tiros = new Tiro[buffer.Length + 1];
                for (int n = 0; n < tiros.Length - 1; n++)
                    tiros[n] = buffer[n];
                tiros[tiros.Length - 1] = tiro; 

            }
            else
            {
                tiros = new Tiro[] { tiro };
            }

            return tiros;
        }

        public static Tiro[] RemoveAtIndex(Tiro[] tiros, int index)
        {
            if (tiros.Length > 1)
            {
                Tiro[] buffer = new Tiro[tiros.Length - 1];
                int a = 0;
                for (int n = 0; n < buffer.Length; n++)
                {
                      if (n != tiros.Length - 1)
                    {
                        
                        if (n == index)
                        {
                            a++;
                        }
                        buffer[n] = tiros[n+a];
                    }
                }
                tiros = buffer;
            }
            else 
                tiros = null;

            return tiros;
        }
    }
}
